package com.example.work2

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class TxlAdapter(val p_msg: ArrayList<P_Msg>) : RecyclerView.Adapter<TxlAdapter.ViewHolder>() {
    inner class ViewHolder(itemView: View):RecyclerView.ViewHolder(itemView){
        val touxiang=itemView.findViewById<ImageView>(R.id.pic2)
        val name=itemView.findViewById<TextView>(R.id.name2)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TxlAdapter.ViewHolder {
        val view=LayoutInflater.from(parent.context).inflate(R.layout.txl_view,parent,false)
        val holder= ViewHolder(view)
        return holder
    }
    override fun onBindViewHolder(holder: TxlAdapter.ViewHolder, position: Int) {
        val p_msg=p_msg[position]
        holder.touxiang.setImageResource(p_msg.imageId)
        holder.name.text=p_msg.name
    }
    override fun getItemCount() = p_msg.size

}